import { Component, OnInit, Injector, TemplateRef, ViewChild, Input   } from '@angular/core';
import { NgZorroPageBaseComponent } from '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { HttpService } from "../../core/service/http.service";
import { Router, NavigationExtras } from "@angular/router";
import {
  AndOr, Compare, ExpressionPair, PagedResultDto, PagerSearchInput, ElementViewType, BaseComponentConfig,
  SystemFormControl, FieldType, ElementShowType, CustomNavigation, ClassInfoOutput, NavigatType, ArSystemFormControl, ClassSchool
} from "../..";
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import {
  FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators,
  FormControl
} from "@angular/forms";
import { StumanagementComponent } from "./stumanagement.component";


@Component({
  selector: 'app-classes-test',
  templateUrl: '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.html',
  styleUrls: ['../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.scss']
})
export class ManagementComponent extends NgZorroPageBaseComponent implements OnInit {

  ngOnInit() {
    this.IniObserver.subscribe(sb => {
      this.getEntityList();
    });
   
   
  }
  constructor(injector: Injector) {
    super(injector,
      new BaseComponentConfig(
        "School/GetAllSchool",
        "School/Create",
        "School/UpdateSchool",
        "School/GetSchool",
        "School/DeleteSchool",
        "id",
        "School",
        "学院管理",
        new Array<CustomNavigation>(
          new CustomNavigation('学院管理', '', ElementShowType.TableOperation, 'anticon anticon-user', NavigatType.Model)
        )
      ),
      new ArSystemFormControl(
        new Array<SystemFormControl>(
          new SystemFormControl("schoolName", "学校名称", FieldType.Text, true, 30, 0, "", "", true, null, null),
          new SystemFormControl("address", "学校地址", FieldType.Text, true, 30, 0, "", "", true, null, null),
        )
      )
    );
  
      
  }


  getNewEntity(): ClassSchool {
    return new ClassSchool();
  }
	async editEntity(id: number) {
    this.router.navigate(['app/management/schooledit'], {
      queryParams: {
          smId: id  
      }
  });
  }


  get viewType(): ElementViewType {
    return this._viewType;
    
  }

  set viewType(value: ElementViewType) {
    this.router.navigate(['app/management/schooleditadd']);
  }
  async navigateCustom(url: string, pid: any) {
    const msgId = this.message.loading('正在获取数据', { nzDuration: 0 }).messageId;
    try {
      const findEntity = await this.httpService.get<ClassSchool>(`${this.componentConfig.GetSingle}?input=${pid}`);
      if (findEntity) {
        const navigationExtras: NavigationExtras = {
          queryParams: { 'id': pid, 'caption': findEntity.schoolName }
        };
        this.router.navigate([url], navigationExtras);
      } else {
        this.message.error('无法确定表单信息！请刷新列表！');
      }
    }
    finally {
      this.message.remove(msgId);
    }
  }

  showModalForComponent(entity: ClassSchool, tag: any) {
    const keyValue = entity.id;
    const subscription = this.nzModalService.create({
      nzTitle: `${entity.schoolName}`,
      nzContent: StumanagementComponent,
      nzComponentParams: {
        pKeyFieldValue: keyValue,
        caption: entity.schoolName
      },
      nzFooter: null,
      nzWidth: document.documentElement.clientWidth - 60,
    });
  }
}
